<?php

/**
* @Author:  	Jackie Chan
* @Email:   	th_jackie@yahoo.com
* @Link: 		http://chienluocweb.com
* @Version: 	
* @copyright:	
* @license:		Commercial
*/
// No direct access
defined('_JEXEC') or die;

jimport('joomla.application.component.view');
JLoader::register('helper_class_name', JPATH_COMPONENT.'/helpers/teamslider.php');
class TeamsliderViewTeams extends JView
{
	protected $items;
	protected $pagination;
	protected $state;

	/**
	 * Method to display the view.
	 *
	 * @param   string  $tpl  A template file to load. [optional]
	 *
	 * @return  mixed  A string if successful, otherwise a JError object.
	 *
	 * @since   1.6
	 */
	public function display($tpl = null)
	{
		// Initialise variables.
		$this->items		= $this->get('Items');
		$this->pagination	= $this->get('Pagination');
		$this->state		= $this->get('State');

		// Check for errors.
		if (count($errors = $this->get('Errors')))
		{
			JError::raiseError(500, implode("\n", $errors));
			return false;
		}
		$this->addToolbar();
		parent::display($tpl);
	}

	/**
	 * Add the page title and toolbar.
	 *
	 * @return  void
	 *
	 * @since   1.6
	 */
	protected function addToolbar()
	{
		require_once JPATH_COMPONENT . '/helpers/teamslider.php';
		$canDo = TeamsliderHelper::getActions();
		$user = JFactory::getUser();
		JToolBarHelper::title(JText::_('COM_TEAMSLIDER_TEAMS_VIEW_HEADER'));
		JToolBarHelper::addNew('team.add');

		if (($canDo->get('core.edit')))
		{
			JToolBarHelper::editList('team.edit');
		}

		if ($canDo->get('core.edit.state'))
		{
			if ($this->state->get('filter.state') != 2)
			{
				JToolBarHelper::publish('teams.publish', 'JTOOLBAR_PUBLISH', true);
				JToolBarHelper::unpublish('teams.unpublish', 'JTOOLBAR_UNPUBLISH', true);
			}

			if ($this->state->get('filter.state') != -1)
			{
				if ($this->state->get('filter.state') == 2)
				{
					JToolBarHelper::unarchiveList('teams.publish');
				}
			}
		}

		if ($canDo->get('core.delete'))
		{
			JToolBarHelper::deleteList('', 'teams.delete', 'JTOOLBAR_DELETE');
		}

		if ($canDo->get('core.admin'))
		{
			JToolBarHelper::preferences('com_teamslider');
		}
	}
}
